package com.example.springblog.model;

import com.example.springblog.constants.Constant;
import lombok.Data;

@Data
public class Result<T> {
    private int code; //状态码，200表示成功，-1表示失败
    private String errorMsg;
    private T data;

    public static<T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(Constant.SUCCESS_CODE);
        result.setErrorMsg("");
        result.setData(data);
        return result;
    }

    public static<T> Result<T> fail(String errorMsg,T data) {
        Result<T> result = new Result<>();
        result.setCode(Constant.FAIL_CODE);
        result.setErrorMsg(errorMsg);
        result.setData(data);
        return result;
    }

    public static<T> Result<T> fail(String errorMsg) {
        Result<T> result = new Result<>();
        result.setCode(Constant.FAIL_CODE);
        result.setErrorMsg(errorMsg);
        return result;
    }
}
